package com.lagou.edu.server;

/**
 * @author 胡益文
 * @since 2021/10/13 15:07
 */
public abstract class LifecycleBase implements  Lifecycle{
    private volatile int state=0;//0:init 1:start 2:started
    protected ClassLoader classLoader = null;
    @Override
    public final synchronized void init() throws Exception {
        try {
            state=1;
            initInternal();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public final synchronized void start() throws Exception {
        if (state==0) {
            init();
        }
        try {
            state=2;
            startInternal();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    protected abstract void initInternal() throws Exception;

    protected abstract void startInternal() throws Exception;
}
